home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / MPW Interfaces / CIncludes / StdIO.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  5.8 KB  |  266 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     StdIO.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1991.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14.  
  15. #ifndef __STDIO__
  16. #define __STDIO__
  17.  
  18. #ifndef NULL
  19. #define NULL 0
  20. #endif
  21.  
  22. #ifndef __size_t__
  23. #define __size_t__
  24. typedef unsigned int size_t;
  25. #endif
  26.  
  27. #ifndef __va_list__
  28. #define __va_list__
  29. typedef char *va_list;
  30. #endif
  31.  
  32.  
  33. /*
  34.  *    The basic data structure for a stream is the FILE.
  35.  */
  36.  
  37. typedef struct {
  38.     int             _cnt;
  39.     unsigned char    *_ptr;
  40.     unsigned char    *_base;
  41.     unsigned char    *_end;
  42.     unsigned short    _size;
  43.     unsigned short    _flag;
  44.     unsigned short    _file;
  45. } FILE;
  46.  
  47.  
  48. /*
  49.  *    fpos_t is a type that can express any position in a file.  A file's
  50.  *    end-of-file marker has type fpos_t.
  51.  */
  52.  
  53. typedef long fpos_t;
  54.  
  55.  
  56. /*
  57.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  58.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  59.  */
  60.  
  61. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  62. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  63. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  64. #define _IONBF        (1<<2)        /* no buffering */
  65. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  66. #define _IOEOF        (1<<4)
  67. #define _IOERR        (1<<5)
  68. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  69. #define _IORW        (1<<7)        /* Enable read/write access */
  70. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  71. #define _IOBINARY    (1<<9)        /* Binary stream */
  72.  
  73.  
  74. /*
  75.  *    Default file buffer sizes used by setbuf() and setvbuf().
  76.  */
  77.  
  78. #define BUFSIZ    1024            /* default file buffer size */
  79. #define _LBFSIZ  100            /* Line buffer size */
  80.  
  81.  
  82. /*
  83.  *    The standard end-of-file indicator.
  84.  */
  85.  
  86. #define EOF        (-1)
  87.  
  88.  
  89. /*
  90.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  91.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  92.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  93.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  94.  *    of digits, all determined at runtime.
  95.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  96.  */
  97.  
  98. #define L_tmpnam    14
  99. #define TMP_MAX        17576
  100.  
  101.  
  102. /*
  103.  *    The minimum number of files that a program is guaranteed to be able to have
  104.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  105.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  106.  *    64K ROM, 128K Macintosh        12 files
  107.  *    64K ROM, 512K Macintosh        40 files
  108.  *    128K ROM                    40 files per volume
  109.  */
  110.  
  111. #define FOPEN_MAX    12
  112.  
  113.  
  114. /*
  115.  *    Maximum length of a file name, including a trailing zero byte.
  116.  */
  117.  
  118. #define FILENAME_MAX    32
  119.  
  120.  
  121. /*
  122.  *    For use by fseek():
  123.  */
  124.  
  125. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  126.  
  127. #define SEEK_CUR    1
  128. #define SEEK_END    2
  129. #define SEEK_SET    0
  130. #endif
  131.  
  132.  
  133. /*
  134.  *    The standard predefined streams.
  135.  */
  136.  
  137. #define stdin        (&_iob[0])
  138. #define stdout        (&_iob[1])
  139. #define stderr        (&_iob[2])
  140.  
  141.  
  142. #ifdef __cplusplus
  143. extern "C" {
  144. #endif
  145.  
  146. /*
  147.  *    Operations on files
  148.  */
  149.  
  150. int remove(const char *filename);
  151. int rename(const char *oldname, const char *newname);
  152. FILE *tmpfile(void);
  153. char *tmpnam(char *s);
  154.  
  155.  
  156. /*
  157.  *    File access functions
  158.  */
  159.  
  160. int fclose(FILE *stream);
  161. int fflush(FILE *stream);
  162. FILE *fopen(const char *filename, const char *mode);
  163. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  164. void setbuf(FILE *stream, char *buf);
  165. int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  166.  
  167.  
  168. /*
  169.  *    Formatted input/output functions
  170.  */
  171.  
  172. int fprintf(FILE *stream, const char *format, ...);
  173. int fscanf(FILE *stream, const char *format, ...);
  174. int printf(const char *format, ...);
  175. int scanf(const char *format, ...);
  176. int sprintf(char *s, const char *format, ...);
  177. int sscanf(const char *s, const char *format, ...);
  178. int vfprintf(FILE *stream, const char *format, va_list arg);
  179. int vprintf(const char *format, va_list arg);
  180. int vsprintf(char *s, const char *format, va_list arg);
  181.  
  182.  
  183. /*
  184.  *    Character input/output functions and macros
  185.  */
  186.  
  187. int fgetc(FILE *stream);
  188. char *fgets(char *s, int n, FILE *stream);
  189. int fputc(int c, FILE *stream);
  190. int fputs(const char *s, FILE *stream);
  191. int getc(FILE *stream);
  192. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  193. int getchar(void);
  194. #define getchar()    getc(stdin)
  195. char *gets(char *s);
  196. int putc(int c, FILE *stream);
  197. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  198.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  199.                         _flsbuf((unsigned char) (x), (p)))
  200. int putchar(int c);
  201. #define putchar(x)    putc((x), stdout)
  202. int puts(const char *s);
  203. int ungetc(int c, FILE *stream);
  204.  
  205.  
  206. /*
  207.  *    Direct input/output functions
  208.  */
  209.  
  210. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  211. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  212.  
  213.  
  214. /*
  215.  *    File positioning functions
  216.  */
  217.  
  218. int fgetpos(FILE *stream, fpos_t *pos);
  219. int fseek(FILE *stream, long int offset, int whence);
  220. int fsetpos(FILE *stream, const fpos_t *pos);
  221. long int ftell(FILE *stream);
  222. void rewind(FILE *stream);
  223.  
  224.  
  225. /*
  226.  *    Error-handling functions and macros
  227.  */
  228.  
  229. void clearerr(FILE *stream);
  230. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  231. int feof(FILE *stream);
  232. #define feof(p)     ((p)->_flag & _IOEOF)
  233. int ferror(FILE *stream);
  234. #define ferror(p)    ((p)->_flag & _IOERR)
  235. void perror(const char *s);
  236.  
  237. /*
  238.  * For macros
  239.  */
  240.  
  241. extern FILE _iob[];
  242. #define _NFILE 20
  243. int _filbuf(FILE *);
  244. int _flsbuf(unsigned char, FILE *);
  245.  
  246. /*
  247.  *    Non-ANSI extensions
  248.  */
  249.  
  250. #ifndef __STDC__
  251.  
  252. #define fileno(p)    (p)->_file
  253. FILE *fdopen(int fildes, const char *mode);
  254. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  255. int getw(FILE *stream);
  256. int putw(int w, FILE *stream);
  257.  
  258. #endif
  259.  
  260. #ifdef __cplusplus
  261. }
  262. #endif
  263.  
  264.  
  265. #endif
  266.